@ECHO OFF

SETLOCAL ENABLEDELAYEDEXPANSION

SET TempDirs="obj???_*_*" "inf???_*_*" "*Debug_x64" "*Release_x64" "*Debug_Win32" "*Release_Win32"
SET TempFiles="*.ncb" "*.suo" "*.aps" "*.user" "build???_*_*.log" "build???_*_*.wrn" "build???_*_*.err" "Build*.htm" "PREfast_defects_???_*_*.*" "prefast???_*_*.*" "*.embed.manifest.res"  "*.intermediate.manifest" "*.embed.manifest" "*.obj" "*.dep" "*.idb" "*.pdb" "*.exe" "*.ilk" "*.sdf" "*.opensdf" "*.log" "*.lastbuildstate" "*.1.tlog"

CALL :deleteTempDirs  "%TempDirs%"
CALL :deleteTempFiles "%TempFiles%"


SETLOCAL DISABLEDELAYEDEXPANSION

EXIT /B 0


:: ============================================================================================= ::

:deleteTempDirs

DIR /S/B/AD %~1 >nul 2>&1 && (
	FOR /F "tokens=*" %%D IN ('DIR /S/B/AD %~1') DO (
		RD /S/Q "%%~D"
		ECHO %%~D
	)
)

EXIT /B 0


:: ============================================================================================= ::

:deleteTempFiles

DIR /S/B/A-DR %~1 >nul 2>&1 && DEL /S/Q/AR %~1
DIR /S/B/A-DH %~1 >nul 2>&1 && DEL /S/Q/AH %~1
DIR /S/B/A-DS %~1 >nul 2>&1 && DEL /S/Q/AS %~1
DIR /S/B/A-D  %~1 >nul 2>&1 && DEL /S/Q/A  %~1

EXIT /B 0


:: ============================================================================================= ::